package org.example.testdemo.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.example.testdemo.mapper.DeclareMapper;
import org.example.testdemo.pojo.Declare;
import org.example.testdemo.pojo.PageReq;
import org.example.testdemo.pojo.combination.DeclareInformation;
import org.example.testdemo.service.DeclareService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class DeclareServiceImpl implements DeclareService {

    @Resource
    private DeclareMapper declareMapper;


    /**
     * 新增申报信息
     * @param declare 申报信息
     * @return 返回0-1的整数
     */
    @Override
    public Integer addDeclare(Declare declare) {
        return declareMapper.insert(declare);
    }

    /**
     * 返回申报信息
     * @param pId 项目编号
     * @param yearId 会计年度
     * @param intervalId 会计区间
     * @param req 分页
     * @param state 项目状态
     * @return 返回一个申报信息的集合
     */
    @Override
    public IPage<DeclareInformation> getDeclareInformation(String pId, String yearId, String intervalId,Integer state, PageReq req,String userId) {
        Page<DeclareInformation> page = new Page<>();
        return declareMapper.getDeclareInformation(pId,yearId,intervalId,state,userId,page);
    }

    /**
     * 使用申报id获取申报信息
     * @param declareId 申报id
     * @return 返回申报信息
     */
    @Override
    public Declare findByDeclareId(String declareId) {
        QueryWrapper<Declare> wrapper = new QueryWrapper<>();
        wrapper.eq("declareId",declareId);
        return declareMapper.selectOne(wrapper);
    }

    /**
     * 修改申报状态
     * @param declare 申报信息
     * @return 返回0-1的整数
     */
    @Override
    public Integer updateState(Declare declare) {
        return declareMapper.updateById(declare);
    }

    /**
     * 根据申报编号删除申报信息
     * @param declareId 申报编号
     * @return 返回0-1的整数
     */
    @Override
    public Integer deleteDeclare(String declareId) {
        return declareMapper.deleteById(declareId);
    }

    /**
     * 获取申报的总费用
     * @param pId 项目编号
     * @return 返回项目申报金额
     */
    @Override
    public BigDecimal getAmount(String pId) {
        return declareMapper.getAmount(pId);
    }

    /**
     * 使用申报id获取申报信息
     * @param declareId 申报id
     * @return 返回申报信息
     */
    @Override
    public DeclareInformation getDeclareInformationSingle(String declareId) {
        return declareMapper.getDeclareInformationSingle(declareId);
    }

    /**
     * 修改申报信息
     * @param declare 申报信息
     * @return 返回0-1的整数
     */
    @Override
    public Integer updateDeclare(Declare declare) {
        return declareMapper.updateById(declare);
    }

    /**
     * 返回待审核的申报信息
     * @param pId 项目编号
     * @param yearId 会计年度
     * @param intervalId 会计区间
     * @param req 分页
     * @param state 项目状态
     * @return 返回一个申报信息的集合
     */
    @Override
    public IPage<DeclareInformation> findByDeclareInformationAll(String pId, String yearId, String intervalId, Integer state, PageReq req, String userId) {
        Page<DeclareInformation> page = new Page<>();
        return declareMapper.findByDeclareInformationAll(pId,yearId,intervalId,state,userId,page);
    }
}
